package hflyeer.controller;

import hflyeer.base.BaseController;
import hflyeer.pojo.entity.SaleChance;
import hflyeer.pojo.query.SaleChanceQuery;
import hflyeer.service.SaleChanceService;
import hflyeer.utils.CookieUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * SaleChanceController
 *
 * @author hflyeer
 * @date 2021-06-10
 * @describe
 */
@Controller
@RequestMapping("/sale_chance")
public class SaleChanceController extends BaseController {

    @Resource
    private SaleChanceService saleChanceService;

    @RequestMapping(value = "/list")
    @ResponseBody
    protected Map<String,Object> getList(SaleChanceQuery query){
        return saleChanceService.querySaleChanceByParams(query);
    }

    @RequestMapping(value = "/add")
    @ResponseBody
    protected Map<String,Object> addSaleChance(SaleChance saleChance, HttpServletRequest request){
        String trueName = CookieUtil.getCookieValue(request,"trueName");
        saleChance.setCreateMan(trueName);
        return saleChanceService.addSaleChance(saleChance);
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    protected Map<String,Object> deleteSaleChance(Integer[] ids){
        System.out.println(ids);
        return saleChanceService.deleteSaleChance(ids);
    }

    @RequestMapping(value = "/update")
    @ResponseBody
    protected Map<String,Object> updateSaleChance(SaleChance saleChance, HttpServletRequest request){
        return saleChanceService.updateSaleChance(saleChance);
    }


    /**
     * 营销机会首页
     * @return
     */
    @RequestMapping("/index")
    protected String index(){
        return "saleChance/sale_chance";
    }

    @RequestMapping("/toSaleChancePage")
    protected String toAddAndUpdateSaleChance(){
        return "saleChance/add_update";
    }

}
